<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<spring:url value="/js/ricerca/ricerca.js" var="jsUrl"></spring:url>
<spring:url value="/js/ricerca/ricerca-ext.js" var="jsUrlExt"></spring:url>
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.
%>
<spring:url value="/images/glyphicons_039_notes.png" var="notes"></spring:url>
<spring:url value="/images/glyphicons_003_user.png" var="user"></spring:url>
<spring:url value="/images/add.png" var="add"></spring:url>
<script src="${jsUrl}" type="text/javascript"></script>

<div class="unit-row">
	<nav class="nav-tabs" style="width:1000px">
		<ul>
			<li><a href="${flowExecutionUrl}&_eventId=news-candidati">News</a></li>
			<li><span>Ricerca Candidati</span></li>
			<li><a href="${flowExecutionUrl}&_eventId=nuovo-candidato">Nuovo Candidato</a></li>
			<li><a href="<c:url value="j_spring_security_logout" />">Logout</a></li>				
		</ul>
	</nav>
	<br />
	<c:if
		test="${not empty requestScope['org.springframework.validation.BindingResult.ricercaForm'].allErrors}">
		<div class="message message-error">
			<span class="close"></span> Sono presenti degli errori nella ricerca!
		</div>
		</c:if>
	<div class="unit-100 unit-centered" style="width:1000px;opacity:0.7;background-color:#FFFFFF;font-weight:bold;">
		<h3 class="head-toc head-toc-start">Ricerca Candidati</h3>
		<form:form id="formRicerca" cssClass="forms forms-columnar"
			action="${flowExecutionUrl}" method="POST" commandName="ricercaForm">
			<fieldset>
				<p class="forms-inline">
					<form:label path="query" cssErrorClass="error">Testo da ricercare</form:label>
					<form:input path="query" cssClass="width-60" maxlength="50"
						cssErrorClass="input-error width-60" />
					<form:errors path="query" cssClass="error"></form:errors>
					<form:hidden id="pagina" path="pagina"/>
					<form:hidden path="recordPerPagina" />
					<form:hidden id="tipoRicerca" path="tipoRicerca"/>		
					<input type="hidden" name="_eventId" id="eventId" value="${ricercaForm.tipoRicerca}"> 
				</p>
				<p class="forms-inline">
					<form:label path="nome" cssErrorClass="error">Nome da ricercare</form:label>
					<form:input id="nome" path="nome" cssClass="input-search width-60" cssErrorClass="input-error width-60" />
				</p>
				<p class="forms-inline">
					<form:label path="cognome" cssErrorClass="error">Cognome da ricercare</form:label>
					<form:input id="cognome" path="cognome" cssClass="input-search width-60" cssErrorClass="input-error width-60" />
				</p>
				<p>	
					<form:radiobutton path="criteria" label="Cerca almeno una parola" cssErrorClass="input-error" value="OR"/>
					<form:errors path="criteria" cssClass="error"></form:errors>
				</p>
				<p>	
					<form:radiobutton path="criteria" label="Cerca tutte le parole" cssErrorClass="input-error" value="AND"/>
					<form:errors path="criteria" cssClass="error"></form:errors>
				</p>
				<p align="right">
					<input type="reset" class="btn" value="Annulla"> 
					<input type="button" id="cercaInIride" class="btn btn-round" value="Cerca in 'Candidati'"/>
					<input type="button" id="cercaTraCandidati" class="btn btn-round" value="Cerca in Orma" />
				</p>
			</fieldset>
			<c:if test="${risultati ne null}">
				<br>
				<h3 id="toc-base" class="head-toc head-toc-start">Risultati
					ricerca</h3>
				<table class="width-75 table-bordered table-hovered" style="width:100%">
					<thead>
						<c:choose>
						<c:when test="${ricercaForm.tipoRicerca != 'cercacandidatialfresco'}">
						<tr>
							<th class="width-70">Dati candidato</th>
							<th class="width-20">Data aggiornamento</th>
							<th class="width-10">&nbsp;</th>
						</tr>
						</c:when>
						<c:otherwise>
							<tr>
							<th class="width-10">Score</th>
							<th class="width-60">Nome del documento</th>
							<th class="width-20">Data creazione</th>
							<th class="width-10">&nbsp;</th>
							<th class="width-10">&nbsp;</th>
						</tr>	
						</c:otherwise>
						</c:choose>
					</thead>
					<tbody>

						<c:if test="${fn:length(risultati) == 0}">
							<tr>
								<td colspan="4">
									<div align="center">
										<strong>Non sono presenti candidati con il filtro
											impostato.</strong>
									</div>
								</td>
							</tr>
						</c:if>
						<c:if test="${fn:length(risultati) > 0}">
						
							<c:forEach var="risultato" items="${risultati}">
								<c:choose>
								<c:when test="${ricercaForm.tipoRicerca != 'cercacandidatialfresco'}">
								<tr>
									<td><c:out value="${risultato.dettaglio}"></c:out></td>
									<td><fmt:formatDate value="${risultato.dataAggiornamento}"
											pattern="dd/MM/yyyy" /></td>
									<td class="handle">
									<c:if test="${not empty risultato.idDocumento}">
									<spring:url value="${flowExecutionUrl}&_eventId=visualizzaDocumento&idDocumento=${risultato.idDocumento}" var="alfrescoDoc"></spring:url>		
									<a href="${alfrescoDoc}" target="blank">
										<img alt="Visualizza documento" src='${notes}' border="0"/>
									</a>
									</c:if>
									<a href="${flowExecutionUrl}&_eventId=dettaglioCandidato&idCandidato=${risultato.idRisultato}">
										<img alt="Visualizza candidato" src="${user}" border="0">
									</a>			
									</td>
								</tr>
								</c:when>
								<c:otherwise>
									<tr>
									<td>
										<fmt:formatNumber type="PERCENT" value="${risultato.score}"></fmt:formatNumber>
									</td>
									<td><c:out value="${risultato.dettaglio}"></c:out></td>
									<td><fmt:formatDate value="${risultato.dataAggiornamento}"
											pattern="dd/MM/yyyy" /></td>
									<spring:url value="${flowExecutionUrl}&_eventId=visualizzaDocumento&idDocumento=${risultato.idDocumento}" var="alfrescoDoc"></spring:url>		
									<td>
									<a href="${alfrescoDoc}" target="blank">
										<img alt="Visualizza documento" src='${notes}' border="0"/>
									</a>
									</td>
									<td>
										<c:if test="${risultato.dbUnlinked == true}">
											<a href="${flowExecutionUrl}&_eventId=gestisciCandidato&idNews=-1&idCandidato=-1&emailCandidato=${risultato.email}&createFromAlfresco=true">
												<img alt="Crea scheda" src='${add}'  height="24" border="0"/>
											</a>
										</c:if>
										<c:if test="${risultato.dbUnlinked == false}">
											<a href="${flowExecutionUrl}&_eventId=dettaglioCandidato&idCandidato=${risultato.idSchedaCandidato}">
												<img alt="Visualizza candidato" src="${user}" border="0">
											</a>
										</c:if>
									</td>
								</tr>
								</c:otherwise>
								</c:choose>
							</c:forEach>
							
						</c:if>
					</tbody>
				</table>

				<ul class="pagination">
				
					<c:if test="${ricercaForm.pagina > 0}">
						<li class="pagination-older"><a id="indietro" href="#">&larr; Indietro</a></li>
					</c:if>
					<c:if
						test="${(ricercaForm.pagina * ricercaForm.recordPerPagina)>=0 and ((ricercaForm.pagina * ricercaForm.recordPerPagina)+ricercaForm.recordPerPagina) < ricercaForm.resultSize}">
						<li class="pagination-newest"><a id="avanti" href="#">Avanti &rarr;</a></li>
					</c:if>
				</ul>
			</c:if>
		</form:form>
	</div>
</div>